//
//  ClassificationVideoInfoView.m
//  HorizonLight
//
//  Created by lanou on 15/9/24.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "ClassificationVideoInfoView.h"

@implementation ClassificationVideoInfoView

- (instancetype)initWithFrame:(CGRect)frame taget:(id)taget action:(SEL)action array:(NSArray *)array indexPath:(NSIndexPath *)indexPath
{
    if (self = [super initWithFrame:frame])
    {
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight / 2)];
        //设置允许滑动
        self.scrollView.scrollEnabled = YES;
        //左右滑动
        self.scrollView.contentSize = CGSizeMake(kScreenWidth * [array count], 0);
        //边界回弹
        self.scrollView.bounces = YES;
        //时候显示水平指示器
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.contentOffset = CGPointMake(kScreenWidth * indexPath.row, 0);
        //播放图片
        for (int i = 0; i < [array count]; i++)
        {
            TouchImageView *touchImgView = (TouchImageView *)[self viewWithTag:1000 + i];
            VideoListModel *mod = array[i];
            [touchImgView sd_setImageWithURL:[NSURL URLWithString:mod.coverForDetail]];
        }
        [self addSubview:self.scrollView];
        
        
        self.playImageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - kPlayImgViewWidth) / 2, (_scrollView.height - kPlayImgViewheight) / 2, kPlayImgViewWidth, kPlayImgViewheight)];
        self.playImageView.image = [UIImage imageNamed:@"player_play@2x"];
        [self addSubview:self.playImageView];
        
        self.blurbackImgView = [[TouchImageView alloc] initWithFrame:CGRectMake(0, _scrollView.bottom, kScreenWidth, self.height - _scrollView.bottom)];
        //标题
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, kEdge, _blurbackImgView.width - 2 * kEdge, kLabelHeight)];
        [self setUpLabel:_titleLabel];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        //分类和时间
        self.classLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, _titleLabel.bottom + kEdge * 2, kScreenWidth - 2 * kEdge, kLabelHeight)];
        [self setUpLabel:_titleLabel];
        //内容简介
        self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(kEdge, _classLabel.bottom + kEdge, kScreenWidth - 2 * kEdge, 4 * kLabelHeight)];
        [self setUpLabel:_titleLabel];
        
        
        //收藏按钮
        self.collectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        //分享按钮
        self.shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.collectButton.frame = CGRectMake(kEdge, _contentLabel.bottom + 2 * kEdge, kIconWidth , kIconHeight);
        self.shareButton.frame = CGRectMake(kScreenWidth / 2, _collectButton.top, kIconWidth, kIconWidth);
        [self.collectButton setBackgroundImage:[UIImage imageNamed:@"FontAwesome_f08a(0)_48"] forState:(UIControlStateNormal)];
        [self.shareButton setBackgroundImage:[UIImage imageNamed:@"Entypo_e73c(0)_48"] forState:(UIControlStateNormal)];
        //加入收藏
        self.collectLabel = [[UILabel alloc]initWithFrame:CGRectMake(_collectButton.right, _collectButton.top, (kScreenWidth - _collectButton.right), kLabelHeight)];
        [self setUpLabel:_titleLabel];
        //分享数量
        self.shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(_shareLabel.right, _collectButton.top, _collectLabel.width, kLabelHeight)];
        [self setUpLabel:_shareLabel];
        
        [self addSubview:self.blurbackImgView];
    }
    return self;
}

#pragma mark-----设置Label的属性
- (void)setUpLabel:(UILabel *)label
{
    //文本颜色
    label.textColor = [UIColor whiteColor];
    //文本居左
    label.textAlignment = NSTextAlignmentLeft;
    //文本字体和大小
    label.font = [UIFont systemFontOfSize:13];
    //文本全部输出
    label.numberOfLines = 0;
    [_blurbackImgView addSubview:label];
}

#pragma mark-----Model赋值
- (void)setValueWithModel:(VideoListModel *)model array:(NSArray *)array
{
    //播放图片
    for (int i = 0; i < [array count]; i++)
    {
        TouchImageView *touchImgView = (TouchImageView *)[self viewWithTag:1000 + i];
        VideoListModel *mod = array[i];
        [touchImgView sd_setImageWithURL:[NSURL URLWithString:mod.coverForDetail]];
    }
    //    [self.settingImageView sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail]];
    //模糊图片
    [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:model.coverBlurred]];
    //标题
    self.titleLabel.text = model.title;
    //分割线
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(15, 45, [self.titleLabel.text length] * 10, 0.5)];
    view.backgroundColor = [UIColor whiteColor];
    [self.contentImageView addSubview:view];
    //类别和时间
    self.classLabel.text =  [NSString stringWithFormat:@"#%@ / %02ld'%02ld\"",model.category, [model.duration integerValue] / 60, [model.duration integerValue] % 60];
    //内容简介
    self.contentLabel.text = model.videoListDescription;
    //点赞数
    self.collectLabel.text = [NSString stringWithFormat:@"%ld", model.collectionCount];
    //分享
    self.shareLabel.text = [NSString stringWithFormat:@"%ld", model.shareCount];
}

@end
